# coding: utf-8

require 'rest-client'

class EmployeeRepo
  attr_reader :id, :name

  def initialize id, name
    @id = id
    @name = name
  end

  def self.all
    site = RestClient::Resource.new("#{Setting.cloap_url}/role")
    JSON.parse(site['user/all'].get)
  end    
  
  def self.[](id)
    founds = all.clone.keep_if {|e| e["login"] == id}
    return self.new(id, "") if founds.empty?
    self.new(id, founds.first["name"])
  end
end

